package iotest.byteio;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.TreeSet;

public class MainTestStudent {

	public static void main(String[] args) {
		test();
	}

	private static void test() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("������ѧ��:");
		int count = scanner.nextInt();
		TreeSet<Student> students = new TreeSet<>();
		for (int i = 0; i < count; i++) {
			System.out.println("���֣�");
			String name = scanner.next();
			System.out.println("���䣺");
			int age = scanner.nextInt();
			Student student = new Student(i, name, age);
			students.add(student);
		}

		BufferedWriter bufferedWriter = null;
		try {
			bufferedWriter = new BufferedWriter(new FileWriter("student.txt"));

			for (Student student : students) {
				bufferedWriter.write(student.toString());
				bufferedWriter.newLine();
			}
			bufferedWriter.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (bufferedWriter != null) {
				try {
					bufferedWriter.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		System.out.println("�ļ��Ѿ�д��");

	}

}
